<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>后台首页</title>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
	<center>
		<form id="upform" onsubmit="return false;" method="post"  >
			<table width="650" cellspacing="0" cellpadding="0" border="0"
				height="300">

				<tbody>
					<tr>
						<td align='right'>用户id:&nbsp;&nbsp;</td>
						<td><input type="text" readonly="readonly" id="userid"
							value="${update.id}" name="userid"></td>
					</tr>
					<tr>
						<td align='right'>用户名:&nbsp;&nbsp;</td>
						<td><input type="text" readonly="readonly"
							value="${update.user_name}" name="username"></td>
					</tr>
					<tr>
						<td align='right'>修改密码:&nbsp;&nbsp;</td>
						<td><input type="password" value="" name="pwd1" id="pwd1" ></td>
					</tr>
					<tr>
						<td align='right'>确认密码:&nbsp;&nbsp;</td>
						<td><input type="password" value="" name="pwd2" id="pwd2"  ></td>
					</tr>
					<tr>
					<td colspan="2"  align="center"><span id = "msg" style="color: red;"></span></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" id="btn_sub" value="修改"
							onclick="return subDate();">&nbsp;&nbsp;<input
							type="button" value="返回"
							onclick="javascript:window.history.back(-1)"></td>
					</tr>
				</tbody>
			</table>
		</form>
	</center>
	<script src="../js/jquery.min.js"></script>
	<script src="../js/check.js"></script>
	<script src="../js/md5.js"></script>
	<script type="text/javascript">
		function subDate(){
			var id = $("#userid").val();
			var pwd1 = $("#pwd1").val();
			var pwd2 = $("#pwd2").val();
			if(pwd1.length < 5){
				$("#msg").html('密码长度不符合要求！');
				return false;
			}else{
				$("#msg").html('');
			}
			if(pwd1 == pwd2){
				$("#msg").html('');
			}else{
				$("#msg").html('两次密码不相同，请重新确认！');
				return fasle;
			}
			document.getElementById("pwd1").value = hex_md5(pwd1).toUpperCase();
			document.getElementById("pwd2").value = hex_md5(pwd2).toUpperCase();
			$.ajax({
                cache: true,
                type: "POST",
                url:"./upuser",
                data:$('#upform').serialize(),
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                	if(data.status > 200){
                		$("#msg").html(data.msg);
                		return false;
                	}
                	if(data.status == 200){
                		$("#btn_sub").remove();
                		$("#msg").html('更新成功');
                		var t1 = window.setInterval(autorun,1000); 
                	}
                }
            });
			return false;
		}
		var itime = 5;
		function autorun(){
			itime = itime - 1;
			$("#msg").html('更新成功，' + itime + '秒后自动返回...' );
			if(itime == 0){
				window.history.back(-1);
			}
		}
		
		
	</script>
</body>
</html>